#ifndef MATERIAL_H
#define MATERIAL_H

/* Copyright (C) 2011 Riccardo Marson

   This file is part of OpenPool, an open-source game of pool. 

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   RICCARDO MARSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
   AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  See Readme.rtf for further information.
  
*/

#include <math.h>
#include <vector>

#include "interfaces.h"
#include "model_obj.h"

// list of classes defined here

class CMaterial;

//holds material properties. used if simpleDraw() is called instead of using and .obj model.

/* TODO this class is a mix of new methods and properties and old ones left to avoid
   breaking the game completely. Remove when done! */

class CMaterial
{
public:
	//init everything to null
	CMaterial();
	CMaterial(const CMaterial &mat_in);
	~CMaterial();

	//standard assigment operator
	CMaterial& operator= (CMaterial& mat_in);

	// TODO: unify materials
	//interface with ModelOBJ::Material. Can be used to copy the material properties stored in an .obj model
	//into the object standard material in order to draw the basic shape with a more complex material.
	//Note: glColorMaterial must be disabled.
	CMaterial& operator= (ModelOBJ::Material mat_in);

	// {
	// the interface is used to open up to script without instancing a material copy script-side
	void SetColor(int red, int green, int blue, int alpha );
	void SetAmbient(float red, float green, float blue, float alpha);
	void SetDiffuse(float red, float green, float blue, float alpha);
	void SetSpecular(float red, float green, float blue, float alpha);
	void SetShininess(float shine);
	void SetGPUProgram(string shaderName);
	void SetSurfaceTransparent(bool alphaon);
	void SetShadowBehaviour(bool cast, bool receive);

	inline bool IsTransparent();
	inline bool SurfaceCastsShadows();
	inline bool SurfaceReceivesShadows();
	inline bool UseShader();
	//}

	//TODO make protected
	int color3ub[4];
	float ambient[4];
	float diffuse[4];
	float specular[4];
	float shininess;

	bool transparent;
	bool castShadows;
	bool receiveShadows;

	string shaderName;
	bool useShader;
	unsigned int gpuProgramID;
};

//------------------------------------------------------------------------------
// Mesh Info
//------------------------------------------------------------------------------

class CMeshInfo
{
public:
	CMeshInfo() :
		hasModel(false) {}
	~CMeshInfo() {}

	// this class is only a data holder, make all public for convenience
	bool hasModel;
	string modelName;
	GLObjectPtr meshRef; // needs to change
	CMaterial defaultMaterial; // one material for the whole object, normally overriden
	// by the surface settings inside the mesh object. Useful for quick passes
	// (shadow depth pass, selection render, ...)

};

#endif // MATERIAL_H
